package com.qishenyuan.competition.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.qishenyuan.competition.dto.FindJobTopicReq;
import com.qishenyuan.competition.utils.JacksonUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

/**
 * <p>
 * 找工作帖子信息表
 * </p>
 *
 * @author qishenyuan
 * @since 2025-03-25
 */
@Getter
@Setter
@TableName("find_job")
public class FindJob implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 自增主键
     */
      @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 用户唯一标识
     */
    private String uid;

    /**
     * 标题
     */
    private String title;

    /**
     * 优势
     */
    private String advantage;

    /**
     * 专业
     */
    private String major;

    /**
     * 期望工作
     */
    private String expectedJob;

    /**
     * 期望工资
     */
    private Integer expectedSalary;

    /**
     * 项目经历
     */
    private String projectExperience;

    /**
     * 教育经历
     */
    private String educationExperience;

    /**
     * 实习经历
     */
    private String internshipExperience;

    /**
     * 证书
     */
    private String certificates;

    /**
     * 发布时间
     */
    private Long createTime;

    /**
     * 修改时间
     */
    private Long modifyTime;

    /**
     * 内容
     */
    private String content;

    /**
     * 0:实习内推;1:兼职推荐;2:创业合作
     */
    private Integer tag;

    /**
     * 0：找人；1：找机会
     */
    private Integer type;

    public static FindJob buildModel(FindJobTopicReq findJobTopicReq){
        FindJob findJob = new FindJob();
        BeanUtils.copyProperties(findJobTopicReq,findJob);
        findJob.setProjectExperience(JacksonUtil.toJson(findJobTopicReq.getProjectExperiences()));
        findJob.setEducationExperience(JacksonUtil.toJson(findJobTopicReq.getEducationExperiences()));
        findJob.setInternshipExperience(JacksonUtil.toJson(findJobTopicReq.getInternshipExperiences()));
        findJob.setCertificates(list2String(findJobTopicReq.getCertificates()));
        findJob.setCreateTime(System.currentTimeMillis());
        findJob.setModifyTime(System.currentTimeMillis());
        return findJob;
    }

    // 把list转换成字符串
    private static String list2String(List<String> imageList) {
        StringBuilder sb = new StringBuilder();
        for (String image : imageList) {
            sb.append(image);
            sb.append(";");
        }
        return sb.toString();
    }

    // 把String转换成list，用“;”分隔开
    private static List<String> string2List(String str) {
        List<String> result = Arrays.asList(str.split(";"));
        result = result.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
        return result;
    }
}
